<script>
	import {
		StorageService
	} from "@/utils/storage";

	// 添加全局状态
	uni.$dbReady = false;

	export default {
		onLaunch: function() {
			// #ifdef APP
			this.initDatabase();
			// #endif
		},
		methods: {
			async initDatabase() {
				try {

					const success = await StorageService.init();
					if (success) {
						uni.$dbReady = true;
						uni.bus.emit("dbReady");
						return;
					}

				} catch (error) {
					uni.showToast({
						title: "数据库初始化失败",
						icon: "none",
					});
				}
			},
		},

		onUnload: function() {
			// 关闭数据库
			StorageService.closeDatabase();
		},
	};
</script>

<style lang="scss">
	page,
	body {
		background-color: #f5f5f5;
		height: 100%;
	}
</style>